package edu.nf.hotel.roomtypedao.impl;

import edu.nf.hotel.roomtype.RoomType;
import edu.nf.hotel.roomtypedao.RoomTypeDAO;
import edu.nf.hotel.util.ConnUtils;
import org.nf.db.util.SqlExecutor;
import org.nf.db.util.result.BeanListHandler;

import java.util.List;

/**
 * @Data 2023-06-20
 * @Author Lsw
 */
public class RoomTypeDaoImpl implements RoomTypeDAO {
    @Override
    public int insert(RoomType roomType) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        String sql = "insert into roomtype_info(roomtype,roomtype_image) values(?,?)";
        return executor.executeUpdate(sql,roomType.getRoomType(),roomType.getRoomTypeImage());
    }

    @Override
    public int update(RoomType roomType) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        String sql = "update roomtype_info set roomtype = ?,roomtype_image=? where roomtype_id=?";
        return executor.executeUpdate(sql,roomType.getRoomType(),roomType.getRoomTypeImage(),roomType.getRoomTypeId());
    }

    @Override
    public int delete(int roomTypeId) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        String sql = "delete from  roomtype_info where roomtype_id = ?";
        return executor.executeUpdate(sql,roomTypeId);
    }

    @Override
    public List<RoomType> selectRoomType() {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        BeanListHandler<RoomType> handler = new BeanListHandler<>(RoomType.class);
        String sql = "select roomtype_id,roomtype,roomtype_image from roomtype_info";
        List<RoomType> list = executor.executeQuery(sql,handler);
        return list;
    }
}
